// 导入创建路由实例方法 创建history模式路由
import { createRouter, createWebHistory } from 'vue-router'
// 导入一级路由组件
import Layout from '@/views/Layout/index.vue'
import Login from '@/views/Login/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
// 引入二级路由组件
import SubCategory from '@/views/SubCategory/index.vue'
// 引入商品详情组件
import Detail from '@/views/Detail/index.vue'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // 配置path和component的映射关系
  routes: [
    {
      path:"/",
      component:Layout,
      // 创建二级路由
      children:[
        {
          // 默认二级路由配置项置空
          path:"",
          component:Home
        },
        // 分类页
        {
          path:"category/:id",
          component:Category
        },
        // 分类的下级路由
        {
          path:"category/sub/:id",
          component:SubCategory
        },
        {
          path:"detail/:id",
          component:Detail
        }
      ]
    },
    {
      path:"/login",
      component:Login
    }
  ],
  // 定制路由滚动行为
  scrollBehavior(){
    return {
      left:0,
      top:0
    }
  }
})

export default router
